<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Sitelogo extends MX_Controller {

    //put your code here


    function sitelogo() {
        parent :: __construct();
        $this->load->model(array('admin_commoncall','admin_settings_model'));
        $this->load->model('settings_model');
        $this->template->set_theme('admin');
        $this->template->set_layout('default');
    	$this->admin_commoncall->check_admin_login();
    }

    function index() {
        
    	$this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('nav_bar','layouts/nav_bar')
                ->set_partial('side_menu','layouts/side_menu')
                ->set_partial('footer','footer/footer')
                ->build('settings/site_logo');
    }

 
    public function do_upload() {
       
       if ($_FILES['userfile']['error'] == 0) {
            $ext = preg_replace("/.*\.([^.]+)$/", "\\1", $_FILES['userfile']['name']);
            //$filename= "sitelogo.".$ext;
            $filename = 'sitelogo';
            
            $config['file_name'] = $filename;
            $config['upload_path'] = './assets/images/';
            $config['allowed_types'] = 'jpg|png|gif|jpeg|';
            $config['overwrite'] = true;
            $config['remove_spaces'] = true;
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('userfile')) {
                $this->session->set_flashdata('message', $this->upload->display_errors('<p class="error">', '</p>'));
            }
            
            //--save--//
            
            $fname = $filename.".".$ext; 
            $this->db->query("delete from web_settings where variable = 'site_logo'");
            
            
            $data = array(
            	'description'	=> 'Site logo',
            	'variable'		=> 'site_logo',
            	'value'			=> $fname			
            		
            		);
            $this->db->insert('web_settings',$data);
            
            redirect('secure/settings/sitelogo');
        } else {
            $this->session->set_flashdata('message', 'Please Choose a correct file');
            redirect('secure/settings/sitelogo');
        }
    }
  

}